#include "DriverConsole.h"

DriverConsole* DriverConsole::_dconsole = NULL;

DriverConsole::DriverConsole() {
	printf("Initializing the console");
	_ds = DriverStation::GetInstance();
	//_dseio = &_ds->GetEnhancedIO();
	_stickLeft = new Joystick(JOYSTICK_PORT_LEFT);
	_stickRight = new Joystick(JOYSTICK_PORT_RIGHT);
}

DriverConsole::~DriverConsole() {
	delete _stickLeft;
	delete _stickRight;
}

DriverConsole* DriverConsole::GetInstance() {
	if (NULL == _dconsole)
		_dconsole = new DriverConsole();
	return _dconsole;
}

float DriverConsole::GetJoystickX(JoystickNum joyHand) {
	if (joyHand == JoystickLeft)
		return _stickLeft->GetX();
	else if (joyHand == JoystickRight)
		return _stickRight->GetX();
	return 0;
}

float DriverConsole::GetJoystickY(JoystickNum joyHand) {
	if (joyHand == JoystickLeft)
		return _stickLeft->GetY();
	else if (joyHand == JoystickRight)
		return _stickRight->GetY();
	return 0;
}

bool DriverConsole::GetButtonState(int btnNum) {
	return _dseio->GetButton(btnNum);
}

float DriverConsole::GetPotential(int potNum) {
	return (float) _dseio->GetAnalogIn(potNum);
}

bool DriverConsole::GetJoystickButton(JoystickNum joyHand, int btnNum) {
	if (joyHand == JoystickLeft)
		return _stickLeft->GetRawButton(btnNum);
	else if (joyHand == JoystickRight)
		return _stickRight->GetRawButton(btnNum);
	return 0;
}
